Garbage Collection

The collector is currently a stop-the-world mark-and-sweep collector. Collection can be triggered by any one of a number of events. The user can trigger a collection if it is known that a lot of garbage has been produced. Alternatively, the memory allocator can initiate garbage collection because an allocation limit has been reached.

In order to collect garbage, the collector examines every cell in the root table. A cell that is free contains a free-list pointer to another cell. Thus, any cell that points into some cell array of the root table does not contain a direct pointer. By contrast, cells that do not point into the root table contain direct pointers. The mark algorithm is invoked on those cells to set the mark bits associated with the reachable data structure.

The traversal algorithm for marking uses explicit stacking and iteration. Every time an object is visited, its mark bit is tested and set. If the object was previously unmarked, the structure tag in the object's allocation header is used to obtain information about internal pointers. Then, the internal pointers are pushed onto the stack and the algorithm continues with the next pointer in the stack.